package com.ws.universal.tools;

import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ws.universal.tools.utils.CacheUtils;
import com.ws.universal.tools.utils.DisplayUtils;
import com.ws.universal.tools.utils.PermissionUtils;

import java.io.File;

/**
 * @author:ws
 * @date: 2021/7/28 15:53
 * @desc
 */
public final class ContextInit {
    public static final String ANDROID_RESOURCE = "android.resource://";
    public static final String SEPARATOR = "/";
    private static Context context;

    public static void initial(Context ctx, String appName) {
        context = ctx;
        PermissionUtils.initial(context);
        CacheUtils.initial(context, appName);
        DisplayUtils.initial(context);

    }

    public static Context getContext() {
        return context;
    }


    public static int getIntDime(int res) {

        return (int) context.getResources().getDimension(res);
    }

    public static int getColor(int res) {

        return context.getResources().getColor(res);
    }

    public static float getFloatDimen(int res) {

        return context.getResources().getDimension(res);
    }


    // 将资源ID转为Uri
    public static Uri resourceIdToUri(int resourceId) {
        return Uri.parse(ANDROID_RESOURCE + ContextInit.getContext().getPackageName() + SEPARATOR + resourceId);
    }

    // 将资源ID转为Uri
    public static void loadFile(String resourceId, ImageView imageView) {
        Glide.with(ContextInit.getContext()).load(new File(resourceId)).into(imageView);
    }
}
